package com.mfin.bom.adapter;

import java.util.Date;

import com.mfin.bom.interfaces.IAddress;
import com.mfin.bom.interfaces.ICustomer;
import com.mfin.bom.interfaces.IFinance;
import com.mfin.bom.objects.Customer;
import com.mfin.vo.ObjectKey;

public class CustomerAdapter extends IIdentifiableAdapter implements ICustomer {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6931847662509590705L;

	Customer wrappedCustomer;

	public CustomerAdapter(Customer c, ObjectKey[] keys) {
		super();
		wrappedCustomer = c;
		ObjectKey[] newKeys = new ObjectKey[2];
		newKeys[0] = keys[0];
		newKeys[1] = new ObjectKey(wrappedCustomer.getId());
		setKeys(newKeys);
	}

	public Customer getCustomer() {
		return wrappedCustomer;
	}

	@Override
	public void setFinance(IFinance bomFinanceInformation) {

		if (bomFinanceInformation != null) {
			FinanceAdapter financeInformationAdapter = (FinanceAdapter) bomFinanceInformation;
			wrappedCustomer.setFinance(financeInformationAdapter.getFinance());
		}
	}

	@Override
	public Long getCustomerId() {
		return wrappedCustomer.getId();
	}

	@Override
	public void setCustomerId(Long customerId) {
		wrappedCustomer.setId(customerId);
	}

	@Override
	public String getFirstName() {
		return wrappedCustomer.getFirstName();
	}

	@Override
	public void setFirstName(String firstName) {
		wrappedCustomer.setFirstName(firstName);
	}

	@Override
	public String getMiddleName() {
		return wrappedCustomer.getMiddleName();
	}

	@Override
	public void setMiddleName(String middleName) {
		wrappedCustomer.setMiddleName(middleName);
	}

	@Override
	public String getLastName() {
		return wrappedCustomer.getLastName();
	}

	@Override
	public void setLastName(String lastName) {
		wrappedCustomer.setLastName(lastName);
	}

	@Override
	public Date getJoinedDate() {
		return wrappedCustomer.getJoinedDate();
	}

	@Override
	public void setJoinedDate(Date joinedDate) {
		wrappedCustomer.setJoinedDate(joinedDate);
	}

	@Override
	public String getMobile() {
		return wrappedCustomer.getMobile();
	}

	@Override
	public void setMobile(String mobile) {
		wrappedCustomer.setMobile(mobile);
	}

	@Override
	public IAddress getCommunicationAddress() {
		return new AddressAdapter(wrappedCustomer.getAddressByComAddressId());
	}

	@Override
	public void setCommunicationAddress(IAddress bomCommunicationAddress) {
		wrappedCustomer
				.setAddressByComAddressId(((AddressAdapter) bomCommunicationAddress)
						.getAddress());
	}

	@Override
	public IAddress getPermanentAddress() {
		return new AddressAdapter(wrappedCustomer.getAddressByPrntAddressId());
	}

	@Override
	public void setPermanentAddress(IAddress bomPermanentAddress) {
		wrappedCustomer
				.setAddressByPrntAddressId(((AddressAdapter) bomPermanentAddress)
						.getAddress());
	}
}
